#include "../src/FileManager.hpp"
#include <fstream>
#include <stdexcept>
#include <iostream>

std::filesystem::path TestPath="/tmp/TEST_FileManager";

void CreateTestFile(std::filesystem::path path)
{
  std::ofstream file(path);
  if(!file.is_open())
    throw std::runtime_error("Can't create test file");
  file.close();
}

int main()
{
  if(std::filesystem::exists(TestPath))
    std::filesystem::remove_all(TestPath);
  std::filesystem::create_directory(TestPath);
  FileManager mang(TestPath,{"1","2","3","4","5"});
  std::cout<<">>>>> Create Test Record"<<std::endl;
  mang.CreateRecord(1);
  mang.CreateRecord(2);
  mang.CreateRecord(3);
  mang.CreateRecord(4);
  mang.CreateRecord(5);
  if(mang.CheckRecordExists(1)
  && mang.CheckRecordExists(2)
  && mang.CheckRecordExists(3)
  && mang.CheckRecordExists(4)
  && mang.CheckRecordExists(5)
  ) {}
  else throw std::runtime_error("Can't Create Test Record");

  std::cout<<">>>>> Create Test Record File"<<std::endl;
  CreateTestFile(TestPath/"1"/"1.mkv");
  CreateTestFile(TestPath/"1"/"2.mkv");
  CreateTestFile(TestPath/"1"/"3.mkv");
  CreateTestFile(TestPath/"1"/"4.mkv");
  CreateTestFile(TestPath/"1"/"5.mkv");
  CreateTestFile(TestPath/"1"/"1.frame");
  CreateTestFile(TestPath/"1"/"2.frame");
  CreateTestFile(TestPath/"1"/"3.frame");
  CreateTestFile(TestPath/"1"/"4.frame");
  CreateTestFile(TestPath/"1"/"5.frame");
  mang.CheckRecordFinish(1);

  std::cout<<">>>>> Create Test Handle File"<<std::endl;
  CreateTestFile(TestPath/"1"/"Pose3D.txt");
  CreateTestFile(TestPath/"1"/"smpl.mp4");
  mang.CheckRecordHandle(1);
}
